
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2025-04-13
 * Time: 19:58
 */
class Counter {
    private static int count;

    public int getCount() {
        return count;
    }
    public void add() {
        count++;
    }
}
public class Demo27 {

    public static void main(String[] args) throws InterruptedException {
        Counter counter = new Counter();
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 50000; i++) {
                //1.一个线程，一把锁 可重入性
                synchronized (counter) {
                    synchronized (counter) {
                        counter.add();
                    }
                }
            }
            System.out.println("t1线程结束");
        });
        t1.start();
        t1.join();
        System.out.println(counter.getCount());
    }
}
